package org.smr.dev;

import java.util.List;

import org.smr.dev.matedata.OrmColumnAndField;
import org.smr.dev.matedata.OrmDef;

public class OrmDefCreator {

	/**
	 * 
	 * @param tableName
	 * @return
	 */
	public OrmDef create(String tableName) {
		List<ColumnModel> columnModels = TableStructUtils.getTableStructure(tableName);
		return transformColumnModels2OrmDef(tableName, columnModels);

	}

	/**
	 * 把 ColumnModel 转换为 EntityDef
	 * 
	 * @param tableName
	 * @param columnModels
	 * @return
	 */
	public OrmDef transformColumnModels2OrmDef(String tableName, List<ColumnModel> columnModels) {
		OrmDef ormDef = new OrmDef();
		for (ColumnModel cm : columnModels) {
			ormDef.getColumnAndAttributeList().add(new OrmColumnAndField(cm.getColumnName(), cm.getFieldName()));
		}
		ormDef.setEntityName(TableStructUtils.tableName2BeanName(tableName));
		ormDef.setTableName(tableName);
		return ormDef;
	}
}